package com.personalink.input.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

/**
 * 输入处理结果DTO
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class InputProcessResult {
    
    /**
     * 用户ID
     */
    private String userId;
    
    /**
     * 会话ID
     */
    private String sessionId;
    
    /**
     * 输入类型
     */
    private String inputType;
    
    /**
     * 处理后的文本内容
     */
    private String processedText;
    
    /**
     * 语音转录文本
     */
    private String transcribedText;
    
    /**
     * 文本分析结果
     */
    private TextAnalysis textAnalysis;
    
    /**
     * 图像分析结果
     */
    private ImageAnalysis imageAnalysis;
    
    /**
     * 语音分析结果
     */
    private VoiceAnalysis voiceAnalysis;
    
    /**
     * 提取的对象列表
     */
    private List<ExtractedObject> extractedObjects;
    
    /**
     * 处理时间戳
     */
    private Long processedAt;
    
    /**
     * 额外元数据
     */
    private Map<String, Object> metadata;
    
    /**
     * 文本分析结果
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class TextAnalysis {
        /**
         * 情感分析
         */
        private SentimentResult sentiment;
        
        /**
         * 意图识别
         */
        private String intent;
        
        /**
         * 关键词提取
         */
        private List<String> keywords;
        
        /**
         * 实体识别
         */
        private List<NamedEntity> entities;
        
        /**
         * 语言检测
         */
        private String detectedLanguage;
        
        /**
         * 文本质量评分
         */
        private Double qualityScore;
    }
    
    /**
     * 图像分析结果
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ImageAnalysis {
        /**
         * 图像描述
         */
        private String description;
        
        /**
         * 检测到的对象
         */
        private List<DetectedObject> objects;
        
        /**
         * 场景分类
         */
        private String sceneCategory;
        
        /**
         * 图像质量评分
         */
        private Double qualityScore;
        
        /**
         * 图像尺寸
         */
        private ImageDimensions dimensions;
        
        /**
         * 颜色分析
         */
        private ColorAnalysis colorAnalysis;
    }
    
    /**
     * 语音分析结果
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class VoiceAnalysis {
        /**
         * 语音质量评分
         */
        private Double qualityScore;
        
        /**
         * 说话人情感
         */
        private SentimentResult emotion;
        
        /**
         * 语音特征
         */
        private VoiceFeatures features;
        
        /**
         * 语言检测
         */
        private String detectedLanguage;
        
        /**
         * 转录置信度
         */
        private Double confidence;
    }
    
    /**
     * 情感分析结果
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class SentimentResult {
        private String label;  // positive, negative, neutral
        private Double score;  // 0.0 - 1.0
        private Map<String, Double> emotions; // joy, anger, sadness, fear, etc.
    }
    
    /**
     * 命名实体
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class NamedEntity {
        private String text;
        private String type;  // PERSON, LOCATION, ORGANIZATION, etc.
        private Double confidence;
        private Integer startIndex;
        private Integer endIndex;
    }
    
    /**
     * 检测到的对象
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class DetectedObject {
        private String label;
        private Double confidence;
        private BoundingBox boundingBox;
    }
    
    /**
     * 边界框
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class BoundingBox {
        private Integer x;
        private Integer y;
        private Integer width;
        private Integer height;
    }
    
    /**
     * 图像尺寸
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ImageDimensions {
        private Integer width;
        private Integer height;
        private String format;
        private Long fileSize;
    }
    
    /**
     * 颜色分析
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ColorAnalysis {
        private String dominantColor;
        private List<String> colorPalette;
        private Double brightness;
        private Double contrast;
    }
    
    /**
     * 语音特征
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class VoiceFeatures {
        private Double pitch;      // 音调
        private Double tempo;      // 语速
        private Double volume;     // 音量
        private String gender;     // 性别识别
        private Integer ageRange;  // 年龄范围
    }
    
    /**
     * 提取的对象
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ExtractedObject {
        private String type;
        private String value;
        private Double confidence;
        private Map<String, Object> attributes;
    }
}